package com.example.ggpicturegg.bottom;

import androidx.appcompat.app.AppCompatActivity;
import com.example.ggpicturegg.R;
import com.example.ggpicturegg.first.RecyclerviewActivity;
import com.example.ggpicturegg.myAdapter.SortAdapter;
import com.example.ggpicturegg.tool.Sidebar;
import com.example.ggpicturegg.tool.User;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.Collections;

public class Talk_b extends AppCompatActivity {

    private TextView frist;
    private TextView myinfo;
    private TextView friend;
    private ImageView im_add_x;

    private ListView listView;
    private Sidebar sideBar;
    private ArrayList<User> list;


    private Bundle bundle1;
    private String sss=null;    // 登录的用户名

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_talk_b);

        transinfo();
        initView();

        initData();



    }

    private void initData() {
        list = new ArrayList<>();
        list.add(new User("亳州")); // 亳[bó]属于不常见的二级汉字
        list.add(new User("大娃"));
        list.add(new User("二娃"));
        list.add(new User("三娃"));
        list.add(new User("四娃"));
        list.add(new User("五娃"));
        list.add(new User("六娃"));
        list.add(new User("七娃"));
        list.add(new User("喜羊羊"));
        list.add(new User("美羊羊"));
        list.add(new User("懒羊羊"));
        list.add(new User("沸羊羊"));
        list.add(new User("暖羊羊"));
        list.add(new User("慢羊羊"));
        list.add(new User("灰太狼"));
        list.add(new User("红太狼"));
        list.add(new User("孙悟空"));
        list.add(new User("黑猫警长"));
        list.add(new User("舒克"));
        list.add(new User("贝塔"));
        list.add(new User("海尔"));
        list.add(new User("阿凡提"));
        list.add(new User("邋遢大王"));
        list.add(new User("哪吒"));
        list.add(new User("没头脑"));
        list.add(new User("不高兴"));
        list.add(new User("蓝皮鼠"));
        list.add(new User("大脸猫"));
        list.add(new User("大头儿子"));
        list.add(new User("小头爸爸"));
        list.add(new User("蓝猫"));
        list.add(new User("淘气"));
        list.add(new User("叶峰"));
        list.add(new User("楚天歌"));
        list.add(new User("江流儿"));
        list.add(new User("Tom"));
        list.add(new User("Jerry"));
        list.add(new User("12345"));
        list.add(new User("54321"));
        list.add(new User("_(:з」∠)_"));
        list.add(new User("……%￥#￥%#"));
        Collections.sort(list); // 对list进行排序，需要让User实现Comparable接口重写compareTo方法
        SortAdapter adapter = new SortAdapter(this, list,sss);
        listView.setAdapter(adapter);
    }


    private void initView() {
        listView = (ListView) findViewById(R.id.userlist);
        sideBar = (Sidebar) findViewById(R.id.sidebar);

        im_add_x = findViewById(R.id.add_x);
        frist = findViewById(R.id.frist_x);
        myinfo = findViewById(R.id.myinfo_x);
        friend = findViewById(R.id.friend_x);
        OnClick onClick = new OnClick();
        frist.setOnClickListener(onClick);
        friend.setOnClickListener(onClick);
        myinfo.setOnClickListener(onClick);
        im_add_x.setOnClickListener(onClick);

        sideBar.setOnStrSelectCallBack(new Sidebar.ISideBarSelectCallBack() {
            @Override
            public void onSelectStr(int index, String selectStr) {
                for (int i = 0; i < list.size(); i++) {
                    if (selectStr.equalsIgnoreCase(list.get(i).getFirstLetter())) {
                        listView.setSelection(i); // 选择到首字母出现的位置
                        return;
                    }
                }
            }
        });
    }

    private void transinfo(){
        bundle1 = getIntent().getExtras();
        sss = bundle1.getString("Re_to_talk");
        if(sss!=null){Log.d("Talk 接受 Re 的name", "    ---------- is ---------    "+ sss);}
        if(sss==null){
            sss = bundle1.getString("friend_to_talk");
            if(sss!=null){ Log.d("Talk 接受 Friend 的name", "    ---------- is ---------    "+ sss);}
        }
        if(sss==null){
            sss = bundle1.getString("talk_to_talk");
            if(sss!=null){ Log.d("Talk 接受 talk 的name", "    ---------- is ---------    "+ sss);}
        }
        if(sss==null){
            sss = bundle1.getString("care_to_talk");
            if(sss!=null){Log.d("Talk 接受 care 的name", "    ---------- is ---------    "+ sss);}
        }
        if(sss==null){
            sss = bundle1.getString("like_to_talk");
            if(sss!=null){ Log.d("Talk 接受 like 的name", "    ---------- is ---------    "+ sss);}
        }
    }



    class OnClick implements View.OnClickListener {
        private Intent intent;
        private Bundle bundle;

        @Override
        public void onClick(View v) {

            switch (v.getId()) {
                case R.id.frist_x:
                    intent = new Intent(Talk_b.this, RecyclerviewActivity.class);
                    Log.d("talk 发送 Re 的name", "    ---------- is ---------    "+ sss);
                    bundle = new Bundle();
                    //bundle.putInt("max_id",ans);
                    bundle.putString("talk_to_Re",sss);
                    intent.putExtras(bundle);
                    startActivity(intent);
                    break;
                case R.id.myinfo_x:
                    intent = new Intent(Talk_b.this, Myinfo.class);
                    Log.d("talk 发送 myinfo 的name", "    ---------- is ---------    "+ sss);
                    bundle = new Bundle();
                    //bundle.putInt("max_id",ans);
                    bundle.putString("talk_to_myinfo",sss);
                    intent.putExtras(bundle);
                    startActivity(intent);
                    break;
                case R.id.friend_x:
                    intent = new Intent(Talk_b.this, Friend_b.class);
                    Log.d("talk 发送 friend 的name", "    ---------- is ---------    "+ sss);
                    bundle = new Bundle();
                    //bundle.putInt("max_id",ans);
                    bundle.putString("talk_to_friend",sss);
                    intent.putExtras(bundle);
                    startActivity(intent);
                    break;
                case R.id.add_x:
                    intent = new Intent(Talk_b.this, Publish_b.class);
                    Log.d("talk 发送 publish 的name", "    ---------- is ---------    "+ sss);
                    bundle = new Bundle();
                    //bundle.putInt("max_id",ans);
                    bundle.putString("talk_to_add",sss);
                    intent.putExtras(bundle);
                    startActivity(intent);
                    break;

            }
        }

        private void SearchFriendImage() {
        }
    }
}